﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PropertyChangedEventArgs
{
    

    class Person:IPropertyChangable
    {
        public event PropertyChangedEventHandler PropertyChange;
        const string PropertyNameName = "Person.Name";
        const string PropertyAgeName = "Person.Age";

        private string name;
        private int age;

        public Person(string name, int age)
        {
            this.name = name;
            this.age = age;

            this.PropertyChange += delegate(object sender, PropertyChangedEventArgs args)
            {
                Console.WriteLine("Name:{0} OldValue:{1} NewValue:{2}", args.Name , args.OldValue , args.NewValue);
            };
        }

        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                OnPropertyChanged(value);
                name = value;
            }
        }
  
        private void OnPropertyChanged(string value)
        {
            if (this.PropertyChange != null)
            {
                this.PropertyChange(this, new PropertyChangedEventArgs(PropertyNameName, this.name, value));
            }
        }

        public int Age
        {
            get
            {
                return age;
            }
            set
            {
                if (this.PropertyChange != null)
                {
                    this.PropertyChange(this, new PropertyChangedEventArgs(PropertyAgeName, this.name, value));
                }
                age = value;
            }
        }

        
    }
}
